/* eslint-disable no-param-reassign */
import React from 'react';
import { connect } from 'dva';
import * as config from '../../utils/config';
import MergeTableEditComponent from '../../components/Common/MergeTableEdit/MergeTableEdit';

function mergeTableEdit({ dispatch, ...props }) {
  function changePage(componentName, value, dataUrl, fastbFilter) {
    dispatch({
      type: 'mergeTable/getFormData',
      payload: {
        componentName, value, dataUrl, fastbFilter,
      },
    });
  }
  function showData(obj) {
    const { tableConfig } = obj;
    obj.dataUrl = tableConfig.formData.dataUrl;
    obj.value = { pageNum: `${config.pageNum}`, pageSize: `${config.pageSize}` };
    dispatch({ type: 'mergeTable/getFormData', payload: obj });
  }
  function EditTable(obj) {
    dispatch({ type: 'mergeTable/editTable', payload: obj });
  }
  function DeleTable(obj) {
    dispatch({ type: 'mergeTable/deleTable', payload: obj });
  }
  function GetNewId() {
    dispatch({ type: 'mergeTable/getNewId' });
  }
  const mergeTableEditProps = {
    ...props,
    onChange: changePage,
    onShowData: showData,
    onEditTable: EditTable,
    onDeleTable: DeleTable,
    onGetNewId: GetNewId,
  };
  return (
    <div>
      <MergeTableEditComponent {...mergeTableEditProps} />
    </div>
  );
}

export default connect(({ app }) =>
  ({ app }))(mergeTableEdit);
